import axios from "axios";
export default function common(){
    this.baseURL= "http://192.168.3.96:9018/",
    this.seat=[
        { value: "NONE", label: "位置绝对" },
        { value: "CLAMP_TO_GROUND", label: "位置固定在地形上" },
        { value: "RELATIVE_TO_GROUND", label: "位置高度是指地形上方的高度" }
    ]
}
common.prototype.switchHeightReference=function(heightReference){
    let res = Cesium.HeightReference.NONE;
    switch (heightReference) {
        case "NONE":
        res = Cesium.HeightReference.NONE;
        break;
        case "CLAMP_TO_GROUND":
        res = Cesium.HeightReference.CLAMP_TO_GROUND;
        break;
        case "RELATIVE_TO_GROUND":
        res = Cesium.HeightReference.RELATIVE_TO_GROUND;
        break;
        default:
        break;
    }
    return res;
}
common.prototype.guid=function() {
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
        /[xy]/g,
        function (c) {
            var r = (Math.random() * 16) | 0,
                v = c == "x" ? r : (r & 0x3) | 0x8;
            return v.toString(16);
        }
    );
}
common.prototype.getSymbolAttributeById=async function (id)  {
        try {
            let res = await axios.get(this.baseURL + "Symbol/GetSymbolAttributeById", {
                params: { id: id }
            });
            let attributeData = res.data;

            let attribute = JSON.parse(attributeData.attribute);
            return attribute;
        } catch (e) {
            console.log(e);
        }
}
//保存符号库属性
common.prototype.saveSymbolAttribute=async function(attrData, isAdd) {
    try {
        let data = {},k,dk,whiteSpace = ["id","name","symbollevelId","imageUrl","type","typeName","attribute"]
        for(k in attrData){
            if(whiteSpace.includes(k)){
                dk = k.charAt(0).toLocaleUpperCase() + k.substring(1)
                data[dk] = attrData[k]
                continue
            }
            data[k] = attrData[k]
        }
        // let data = {
        //     Id: attrData.id,
        //     // Name: attrData.name,
        //     // SymbollevelId: attrData.symbollevelId,
        //     // ImageUrl: attrData.imageUrl,
        //     Type: attrData.type,
        //     TypeName: attrData.typeName,
        //     Attribute: attrData.attribute,
        // };
        // if (attrData.name) {
        //     data.Name = attrData.name;
        // }
        // if (attrData.symbollevelId) {
        //     data.SymbollevelId = attrData.symbollevelId;
        // }
        // if (attrData.imageUrl) {
        //     data.ImageUrl = attrData.imageUrl;
        // }
        // if (attrData.remarks) {
        //     data.Remarks = attrData.remarks;
        // }
        
       
        let path = this.baseURL + (isAdd ? "Symbol/AddSymbolAttribute" : "Symbol/EditSymbolAttribute")
        // if (isAdd) {
        //     res = await axios.post(this.baseURL + "Symbol/AddSymbolAttribute", data);
        // } else {
        //     res = await axios.post(this.baseURL + "Symbol/EditSymbolAttribute", data);
        // }
        let res = await axios.post(path, data);
        return res.data;
    } catch (e) {
        console.log(e);
    }
}
    //删除符号库属性
common.prototype.deleteSymbolAttribute=async function(id) {
    try {
        let res = await axios.delete(this.baseURL + "Symbol/DeleteSymbolAttribute", {
            params: {
                id: id
            }
        });
        return res.data;
    } catch (e) {
        console.log(e);
    }
}
common.prototype.getLngLat=function (position) {
    const {
        longitude,
        latitude,
        height
    } = Cesium.Cartographic.fromCartesian(position)
    const lng = Cesium.Math.toDegrees(longitude)
    const lat = Cesium.Math.toDegrees(latitude)
    return [lng, lat, height]
}
